<template>
  <div class="wrapper">
    <div class="header-box">
      <header>
        <i class="fa fa-angle-left" onclick="history.go(-1)"></i>
        <p>历史反馈信息列表</p>
        <i class="fa fa-th" @click="toSelectGrid"></i>
      </header>
      <div class="top-ban"></div>
      <img src="../assets/header.png">
    </div>

    <ul>
      <li v-for="aqiFeedback in aqiFeedbackArr" :key="aqiFeedback.afId"  @click="showDetail(aqiFeedback)">
        <div>
          <i :style="{backgroundColor: aqiFeedback.aqi.color}">{{aqiFeedback.aqi.chineseExplain}}</i>
          <span>{{aqiFeedback.afDate}} {{aqiFeedback.afTime}}</span>
        </div>
        <div>{{aqiFeedback.gridProvince.provinceName}}</div>
        <div>{{aqiFeedback.gridCity.cityName}}</div>
      </li>
    </ul>
    <!-- 详情弹窗 -->
    <div class="modal" v-if="showModal" @click.self="closeModal">
      <div class="modal-content">
        <h3>反馈详情</h3>
        <div class="detail-item">
          <label>空气质量指数级别:</label>
          <span :style="{color: currentFeedback.aqi.color}">
            {{currentFeedback.aqi.chineseExplain}}
          </span>
        </div>
        <div class="detail-item">
          <label>反馈时间:</label>
          <span>{{currentFeedback.afDate}} {{currentFeedback.afTime}}</span>
        </div>
        <div class="detail-item">
          <label>地区:</label>
          <span>{{currentFeedback.gridProvince.provinceName}} {{currentFeedback.gridCity.cityName}}</span>
        </div>
        <div class="detail-item">
          <label>反馈内容:</label>
          <p class="information">{{currentFeedback.information}}</p>
        </div>
        <div class="detail-item">
          <label>网格员:</label>
          <span v-if="currentFeedback.gmId === 0">未分配</span>
          <span v-else>
            {{currentFeedback.gridMember.gmName}} (分配时间: {{currentFeedback.assignDate}} {{currentFeedback.assignTime}})
          </span>
        </div>
        <button @click="closeModal">关闭</button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, inject } from "vue";
import { useRouter } from "vue-router";
import { getSessionStorage } from "../common.js";

const router = useRouter();
const axios = inject("axios");
const supervisor = getSessionStorage('supervisor');

const aqiFeedbackArr = ref([]);
const showModal = ref(false);
const currentFeedback = ref({});
const init = ()=>{
  axios
      .post("aqiFeedback/listAqiFeedbackByTelId", {
        telId: supervisor.telId
      })
      .then((response) => {
        aqiFeedbackArr.value = response.data;
      })
      .catch((error) => {
        console.log(error);
      });
}
init();

const toSelectGrid = ()=>{
  router.push('/selectGrid');
}
const showDetail = (feedback) => {
  currentFeedback.value = feedback;
  showModal.value = true;
};

const closeModal = () => {
  showModal.value = false;
};
</script>

<style scoped>
ul{
  width: 100%;
  background-color: #FFF;
  color: #555;
  overflow: hidden;
}
ul li{
  width: 100%;
  border: solid 1px #C6E2FF;
  box-sizing: border-box;
  padding: 1vw 2vw;
  font-size: 3.8vw;

  display: flex;
  justify-content: space-between;

  margin: 2vw 0;
  background-color: #ECF5FF;
  border-radius: 1vw;
}
ul li div{
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
ul li div:first-child{
  flex: 2;
}
ul li div i{
  display: block;
  box-sizing: border-box;
  padding: 1.5vw 2vw;
  font-size: 3.2vw;
  font-weight: 700;
  border-radius: 1vw;
  color: #FFF;
  margin-right: 2vw;
  background-color: red;
  font-style: normal;
}
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-content {
  background-color: white;
  padding: 20px;
  border-radius: 8px;
  width: 80%;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-content h3 {
  margin-top: 0;
  color: #333;
  text-align: center;
}

.detail-item {
  margin-bottom: 15px;
}

.detail-item label {
  font-weight: bold;
  margin-right: 10px;
  color: #666;
}

.information {
  white-space: pre-wrap;
  margin-top: 5px;
  padding: 10px;
  background-color: #f5f5f5;
  border-radius: 4px;
}

button {
  display: block;
  margin: 20px auto 0;
  padding: 8px 20px;
  background-color: #409EFF;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

button:hover {
  background-color: #66b1ff;
}
</style>